<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/9/9 0009
 * Time: 下午 3:48
 */

namespace App\Http\Controllers\Index;


use App\Model\Article;
use App\Model\UserArticle;

class ArticleController extends CommonController
{
    /**
     * @title 搜索文章列表页
     * @param $key
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function searchArticle($key)
    {
        $list = Article::where('title','like',"%$key%");
        return view('index.',['list'=>$list]);
    }

    /**
     * @title 公共文章详情
     * @param $id
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function articleDetails($id)
    {
        $res = Article::find($id);
        return view('index.',['res'=>$res]);
    }

    /**
     * @title 查看用户文章详情
     * @param $uid
     * @param $aid
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function useArticleDetails($uid, $aid)
    {
        $res = UserArticle::with('user','article')->where(['uid'=>$uid,'aid'=>$aid])->first();
        return view('index.',['res'=>$res]);
    }
}